﻿using OverStore.Runtime.PersistenceServiceProvider;
using OverStore.Runtime.Storage;

namespace OverStore.Runtime.ObjectRepository.Mapping
{    
    /// <summary>
    /// Provide method for get object data as key-result pair set
    /// and write data represented as key-result pairs to object data.
    /// </summary>
    /// <typeparam name="TInstance">The type of the instance can be converted.</typeparam>
    /// <remarks>
    /// Good implementation of <see cref="IMapper{TInstance}"/> greatly affects perfomance.
    /// Avoid unnessesary arguments checking and other perfomance expence opeations.
    /// </remarks>
    public interface IMapper<TInstance> : IRuntimeComponent
        where TInstance : class
    {
        /// <summary>
        /// Get data of object.
        /// Operation should not checks arguments for null etc for
        /// gain performance.
        /// </summary>
        /// <param name="instance">The instance to get data.</param>
        /// <param name="registry">The object allows to perform persistence operations over instances of different types.</param>
        /// <returns>The data of instance.</returns>
        /// <exception cref="PersistingRuntimeException">Error occured during mapping.</exception>
        IRecord GetObjectData(TInstance instance, IRegistry registry);

        /// <summary>
        /// Apply data to object.
        /// Operation should not checks arguments for null etc for
        /// gain performance.
        /// </summary>
        /// <param name="data">The data for apply to result.</param>
        /// <param name="result">The result object for apply data to it.</param>
        /// <param name="registry">The object allows to perform persistence operations over instances of different types.</param>
        /// <exception cref="PersistingRuntimeException">Error occured during mapping.</exception>
        void ApplyObjectData(TypedRecord data, TInstance result, IRegistry registry);
    }
}